package com.example.hello;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;

public class sporttask implements Runnable{
    private Handler handler;
    private static final String TAG ="sports" ;
    public void setHandler(Handler handler) {
        this.handler = handler;}
    @Override
    public void run() {
        Document doc = null;
        ArrayList<HashMap<String,String>> sportsItems = new ArrayList<HashMap<String, String>>();
        try {
            doc = Jsoup.connect("http://www.yacou.net/yy/yy2/4-rcyd/index.htm").get();
            Log.i(TAG,"run:title=" + doc.title());

            Elements tables = doc.getElementsByTag("table");//获取table对象
                Element table = tables.get(7);
                Elements td = table.getElementsByTag("td");
                for (int y =5;y<76; y +=2) {

                    HashMap<String, String> sp_map = new HashMap<String, String>();
                    sp_map.put("sportTitle", td.get(y).text());
                   sp_map.put("sportDetail", td.get(y + 1).text());
                   sportsItems.add(sp_map);

                }
            Log.i(TAG,"run:title=" + sportsItems);

              } catch (IOException e) {
            e.printStackTrace();
        }
        Message msg = handler.obtainMessage(8,sportsItems);
        handler.sendMessage(msg);

    }
}
